1468N - Waste Sorting - CodeForces Solution


greedy implementation *900

Please click on ads to support us..

C++ Code:

 #include<bits/stdc++.h>
using namespace std;
 
#define pr pair<int,int>
#define mp make_pair  
#define PI 3.141592653589793238462
#define Nmax 1e18
#define LMAO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout.precision(20),cout.setf(ios::fixed)
#define ll long long
#define lld long double
#define eb emplace_back
#define pb push_back
#define nl "\n"
const int M=1e9+7;
 
/*
const int N=1e7+1;
int spf[N]={0};
void createspf(){ 
    for(int i=2;i<N;i++){
        spf[i]=i;
    }
 
    for(int i=2;i*i<=N-1;i++){
        if(spf[i]==i){
            for(int j=i*i;j<=N-1;j+=i){
                if(spf[j]==j)
                spf[j]=i;
            }
        }
    }
 
}
*/
 
/*
const int N=1e5;
vector<bool> v(N+1,0);
vector<int> ans;
void crsieve(){
 
    for(int i=2;i<=N;i++){
        v[i]=true;
    }
 
    for(int j=2;j*j<=N;j++){
        if(v[j]){
            ans.eb(j);
            for(int i=j*j;i<=N;i+=j){
                v[i]=false;
            }
        }
    }
// doen with all primes till 100000
}
*/
 
 
ll int binexp(ll int x, ll int y,ll int mod){
    ll int res=1;
    while(y>0){
        if(y&1)
        res=(res*x)%mod;
        x=(x*x)%mod;
        y>>=1;
    }
 
return res;
}
 
 
const int N=1e6;
ll int fact[N+1];
ll int invfact[N+1];


void facto(){
    fact[0]=1;
for(int i=1;i<=N;i++){
fact[i]=( fact[i-1]*i)%M;
}
}
 
void invfacto(){
    // a-1 == a(p-2) %m-2
    invfact[0]=1;
   for(int i=1;i<=N;i++){
    invfact[i]= binexp(fact[i],M-2,M);
   }
 
}
 
void SOLVE(){
  int c1,c2,c3,a1,a2,a3,a4,a5;
  cin>>c1>>c2>>c3>>a1>>a2>>a3>>a4>>a5;
  bool flag=true;
    c1-=a1;c2-=a2;c3-=a3;
    int req1=0,req2=0;
    if(c1>=0 &&c2>=0 && c3>=0){
        // a4 a5
        req1= (c1+c3)-a4;
        if(req1>=0){
            if(a4>=c1){
                a4-=c1;
                c1=0;
                c3-=a4;
                if(c3>=0){
                    if(c3+c2<a5){
                        flag=false;
                    }
                }
                else{
                    flag=false;
                }
            }
            else{
                a4=0;
                req2=c2+c3-a5;
                if(req2<0){
                    flag=0;
                }
            }
        }
        else
        flag=false;
    }
    else
    flag=false;

    if(flag)
    cout<<"YES"<<nl;
    else
    cout<<"NO"<<nl;

}
 
int main(){
    LMAO;
    //createspf(); 
    //crsieve();    
    //facto();
    //invfacto();
    
    int T=1;//
    cin>>T; //activating multiple test cases;

    while(T--){
        SOLVE();
    }

 return 0;
}


Comments

Submit
0 Comments
More Questions

1326B - Maximums
1635C - Differential Sorting
961A - Tetris
1635B - Avoid Local Maximums
20A - BerOS file system
1637A - Sorting Parts
509A - Maximum in Table
1647C - Madoka and Childish Pranks
689B - Mike and Shortcuts
379B - New Year Present
1498A - GCD Sum
1277C - As Simple as One and Two
1301A - Three Strings
460A - Vasya and Socks
1624C - Division by Two and Permutation
1288A - Deadline
1617A - Forbidden Subsequence
914A - Perfect Squares
873D - Merge Sort
1251A - Broken Keyboard
463B - Caisa and Pylons
584A - Olesya and Rodion
799A - Carrot Cakes
1569B - Chess Tournament
1047B - Cover Points
1381B - Unmerge
1256A - Payment Without Change
908B - New Year and Buggy Bot
979A - Pizza Pizza Pizza
731A - Night at the Museum